<template>
  <div>
    <el-dialog :visible.sync="dialogVisible" class="dialog" @close="close()" v-loading="loading">
      <el-container style="height: 100%;background-color:#fff;" class="box">
        <el-header style="border-bottom: 1px solid #ddd;height:45px;line-height: 45px;">
          <span style="font-size:16px;
            font-family:Microsoft YaHei;
            font-weight:bold;
            color:rgba(51,51,51,1);">信息详情</span>
        </el-header>
        <el-main class="pd0">
          <div class="win-warp" style="height:320px; ">
            <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-form" disabled>
              <el-row :gutter="20" class="row-bg" type="flex">
                <el-col :span="12">
                  <el-form-item label="区域:" label-width="90px" prop="areaName">
                    <el-input ref="areaName" v-model="form.areaName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="楼宇:" label-width="90px" prop="buildName">
                    <el-input maxlength="20" v-model="form.buildName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="房间号:" label-width="90px" prop="roomNum">
                    <el-input maxlength="20" v-model="form.roomNum"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20" class="row-bg" type="flex">
                <!-- <el-col :span="12">
                  <el-form-item label="房间类型:" label-width="90px" prop="typeName">
                    <el-input ref="typeName" v-model="form.typeName"></el-input>
                  </el-form-item>
                </el-col> -->
                <el-col :span="12">
                  <el-form-item label="使用面积:" label-width="90px" prop="usableArea">
                    <el-input maxlength="20" v-model="form.usableArea"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="房屋用途:" label-width="90px" prop="houseUseName">
                    <el-input maxlength="20" v-model="form.houseUseName"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20" class="row-bg" type="flex">
                <el-col :span="12">
                  <el-form-item label="使用部门:" label-width="90px" prop="useDeptName">
                    <el-input ref="name" v-model="form.useDeptName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="联系人:" label-width="90px" prop="checkInUser">
                    <el-input maxlength="20" v-model="form.checkInUser"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="联系电话:" label-width="90px" prop="checkInUserPhone">
                    <el-input maxlength="20" v-model="form.checkInUserPhone"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <el-row style="width: 100%;height: 100%;" :gutter="10">
              <span style="font-size:16px;
                font-family:Microsoft YaHei;
                font-weight:bold;
                color:rgba(51,51,51,1);
                margin-left:15px">完善使用人</span>
              <mainTable ref="mainTable" :dataList="form.houseRoomInUses"></mainTable>
            </el-row>
          </div>
        </el-main>
      </el-container>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addBtn('form')">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import mainTable from "@/views/home/meReview/mainTable";
import { transactionApi } from "@/api/home/transaction";

export default {
  components: {
    mainTable,
  },
  props: {
    form: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      rules: {
        houseUseName: [{ required: true }],
        useDeptName: [{ required: true }],
        checkInUser: [{ required: true }],
        checkInUserPhone: [{ required: true }],
      },
    };
  },
  methods: {
    //按钮事件
    toolButtonClick(text) {
      switch (text) {
        case "关闭":
          this.FormVisible = false;
          break;
      }
    },
    close() {},
    addBtn(form) {
      this.loading = true;

      let data = { houseRoomInUses: [], roomInId: "" };
      this.form.houseRoomInUses.forEach((item) => {
        let obj = {};
        obj.id = item.id;
        obj.phone = item.phone;
        obj.remark = item.remark;
        obj.roomInId = item.roomInId;
        obj.titleId = item.titleId;
        obj.titleName = item.titleName;
        obj.useName = item.useName;
        data.houseRoomInUses.push(obj);
      });
      data.roomInId = this.form.id;
      console.log(data);
      transactionApi
        .roomInUserSave(data)
        .then((res) => {
          if (res.status == "success") {
            this.$message.success(res.data);
            this.dialogVisible = false;
            this.loading = false;
          }
        })
        .catch((error) => {
          this.loading = false;
        });
    },
  },
  created() {},
};
</script>
<style lang="scss" scoped>
.dialog {
  // width: 80%;
  height: 800px;
}
</style>
